package top.yekongle.feature.java8.lambda;

import org.junit.Test;

import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.TreeSet;

public class LambdaTest1 {

    // 原来的匿名内部类
    public void test1() {
        Comparator<Integer> com = new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return Integer.compare(o1, o2);
            }
        };
        TreeSet<Integer> ts = new TreeSet<>(com);
    }

    // Lambda表达式
    public void test2() {
        Comparator<Integer> com = (x,y) -> Integer.compare(x,y);
        TreeSet<Integer> ts = new TreeSet<>(com);
    }

    // 需求： 获取当前公司的员工年龄大于35的员工信息
    List<Employee> employees = Arrays.asList(
            new Employee("张三", 18, 5555.55, null),
            new Employee("李四", 19, 6666.66, null)
    );

    public void test7() {
        employees.stream().filter((e) -> e.getSalary() >=5000).forEach(System.out::println);

        System.out.println("--------------------------------------------");

        employees.stream().map(Employee::getName).forEach(System.out::println);
    }

}
